package com.fenghongzhang.day005;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import android.os.Bundle;

import com.fenghongzhang.day005.fragment.OneFragment;
import com.fenghongzhang.day005.fragment.ThreeFragment;
import com.fenghongzhang.day005.fragment.TwoFragment;
import com.flyco.tablayout.SlidingTabLayout;

import java.util.ArrayList;
import java.util.List;

public class Main2Activity extends AppCompatActivity {
    private SlidingTabLayout tab;
    private ViewPager vp;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);

        tab = (SlidingTabLayout) findViewById(R.id.tab);
        vp = (ViewPager) findViewById(R.id.vp);

//        List<String> name = new ArrayList<>();
//        name.add("首页");
//        name.add("视频");
//        name.add("我的");

        String[] strings = new String[]{"我的","视频","首页"};

        List<Fragment> list = new ArrayList<>();
        list.add(new OneFragment());
        list.add(new TwoFragment());
        list.add(new ThreeFragment());

        //设置缓存的数量
//        vp.setOffscreenPageLimit(1);
        MyAdapter myAdapter = new MyAdapter(getSupportFragmentManager(),FragmentPagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT,list);
        vp.setAdapter(myAdapter);

        tab.setViewPager(vp,strings);

    }

    @Override
    protected void onStart() {
        super.onStart();
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    @Override
    protected void onStop() {
        super.onStop();
    }

    @Override
    protected void onRestart() {
        super.onRestart();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
